package com.xc.pay.ali.h5;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.xc.pay.ali.modal.AliH5PayModal;
import com.xc.pay.common.PayUrl;

public class AliH5Pay {

    public String h5_pay(AliH5PayModal payModal){

        AlipayClient client = new DefaultAlipayClient(PayUrl.SERVER_URL, payModal.getAppid(),
                payModal.getApp_private_key(), PayUrl.FORMAT, PayUrl.CHARSET, payModal.getApp_publice_key(), PayUrl.SIGN_TYPE);
        AlipayTradeWapPayRequest alipay_request = new AlipayTradeWapPayRequest();
        // 封装请求支付信息
        AlipayTradeWapPayModel model=new AlipayTradeWapPayModel();
        model.setOutTradeNo(payModal.getOutTradeNo());
        model.setSubject(payModal.getSubject());
        model.setTotalAmount(payModal.getTotal_amount());
        model.setBody(payModal.getBody());
        model.setTimeoutExpress("30m");
        model.setProductCode(payModal.getProduct_code());
        alipay_request.setBizModel(model);
        // 设置异步通知地址
        alipay_request.setNotifyUrl(payModal.getNotify_url());
        // form表单生产
        String form = "";
        try {
            // 调用SDK生成表单
            form = client.pageExecute(alipay_request).getBody();
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        return form;
    }

}
